<template>
    <div class="app-container">
      <el-card style="margin: 8px">
        <el-row>
          <h1>上海数据分中心固定资产详情</h1>
        </el-row>
        <el-row>
          <el-col :span="12" >
            <div style="margin-bottom: 10px">
               <span class="notes">分中心固定资产编号：</span>{{routeQuery.assetTagNumber}}
            </div>
            <el-row>
              <span class="notes">设备状态：</span>
              <dict-tag style="display: inline-block" :options="dict.type.fa_status" :value="routeQuery.status"/>
            </el-row>
          </el-col>
          <el-col :span="12" style="text-align: right">
            <!-- <el-button :size="size" type="primary">打印</el-button> -->
            <!-- <el-button :size="size">导出</el-button> -->
            <el-button @click="returnGo" :size="size">关闭</el-button>
          </el-col>
        </el-row>
      </el-card>

      <el-tabs tab-position="top" :value="'form'">
        <el-tab-pane label="表单信息" name="form">
          <el-skeleton v-if="formLoading" :rows="6" animated />
          <div v-if="formOpen">
            <el-card
              class="box-card"
              shadow="never"
              v-for="(formInfo, index) in processList"
              :key="index"
            >
              <div slot="header" class="clearfix">
                <div class="headerTitle">
                  <div>
                    <span>{{ formInfo.title }}</span>
                  </div>
                  <div v-if="editFlag === 0">
                    <!-- <el-button v-if="formOpen" size="mini" type="info" v-hasPermi="['workflow:process:print']" @click="printClick(formInfo,index)">打印</el-button> -->
                  </div>
                </div>

              </div>
              <!--流程处理表单模块-->
              <el-col :span="20" :offset="2">
                <!-- <parser :form-conf="formInfo" /> -->
                <!-- <div id="printBox"> -->
                  <v-form-render v-if="formOpen" :form-json="formInfo.fields" :form-data="formInfo.field" ref="vFormRefSubmit"></v-form-render>
                <!-- </div> -->
              </el-col>
            </el-card>
          </div>
          <div v-if="processed === true">
            <el-card class="box-card" shadow="hover" v-show="taskFormData != null && taskFormData.showFormLocalScope == true">
              <div slot="header" class="clearfix">
                <span>填写表单</span>
              </div>
              <el-col :span="20" :offset="2" v-if="formOpen">
                <v-form-render  :form-json="taskFormData.fields" :form-data="taskFormData.field" ref="vFormRefs"></v-form-render>
              </el-col>
            </el-card>
            <div v-if="editFlag === 0">
              <!-- <div v-if="approvalStatus == '12'">
                <el-row :gutter="10" type="flex" justify="center">
                  <el-col :span="1.5">
                    <el-button  icon="el-icon-circle-check" type="success" @click="handleEnsure">确认</el-button>
                  </el-col>
                </el-row>
              </div> -->
              <div v-if="otherConfig !== null">
                <el-row :gutter="10" type="flex" justify="center">
                  <el-col :span="1.5">
                    <el-button  icon="el-icon-circle-check" type="success" @click="handleComplete('0',otherConfig.specialBtn)">{{otherConfig.specialBtn}}</el-button>
                    <!-- <el-button  icon="el-icon-circle-check" type="success" @click="handleComplete">处理</el-button> -->
                  </el-col>
                </el-row>
              </div>
              <el-card class="box-card" shadow="hover"  v-show="otherConfig == null">
                <div slot="header" class="clearfix">
                  <span>审批流程</span>
                </div>
                <el-row>
                  <el-col :span="20" :offset="2">
                    <el-form ref="taskForm" :model="taskForm" :rules="rules" label-width="120px">
                      <el-form-item label="审批意见" prop="comment">
                        <el-input
                          type="textarea"
                          :rows="5"
                          v-model="taskForm.comment"
                          placeholder="请输入 审批意见"
                        />
                      </el-form-item>
                    </el-form>
                  </el-col>
                </el-row>
                <!-- 按钮功能 -->
                <el-row :gutter="10" type="flex" justify="center">
                  <el-col :span="1.5">
                    <el-button  icon="el-icon-circle-check" type="success" @click="handleComplete('0')">通过</el-button>
                    <el-button icon="el-icon-refresh-left" type="warning" @click="handleComplete('1')">退回</el-button>
                  </el-col>
                </el-row>
              </el-card>
            </div>
            <div v-if="editFlag === 1">
              <!-- <el-card class="box-card" shadow="hover"> -->
                <!-- 按钮功能 -->
                <el-row :gutter="10" type="flex" justify="center">
                  <el-col :span="1.5">
                    <el-button type="info" icon="el-icon-circle-plus-outline" @click="handleupdateForm">暂存</el-button>
                    <el-button  icon="el-icon-circle-check" type="primary" @click="handleCompleteSubmit">提交</el-button>
                  </el-col>
                </el-row>
              <!-- </el-card> -->
            </div>

          </div>
          <div v-if="processed === false && approvalStatus == '归档'">
                <el-row :gutter="10" type="flex" justify="center">
                  <el-col :span="1.5">
                     <el-button type="info" icon="el-icon-printer"  @click="printClick()">打印</el-button>
                  </el-col>
                </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane label="流转记录" name="record">
          <el-skeleton v-if="formLoading" :rows="6" animated />
          <el-card class="box-card" shadow="never">
            <el-col :span="20" :offset="2">
              <div class="block">
                <el-timeline>
                  <el-timeline-item
                    v-for="(item,index) in historyProcNodeList"
                    :key="index"
                    :icon="setIcon(item.endTime)"
                    :color="setColor(item.endTime)"
                  >
                    <p style="font-weight: 700">{{ item.activityName }}</p>
                    <el-card
                      v-if="item.activityType === 'startEvent'"
                      class="box-card"
                      shadow="hover"
                    >{{ item.assigneeName }} 在 {{ item.createTime }} 保存</el-card>
                    <el-card v-if="item.activityType === 'userTask'" class="box-card" shadow="hover">
                      <el-descriptions :column="5" :labelStyle="{'font-weight': 'bold'}">
                        <el-descriptions-item label="实际办理">{{ item.assigneeName || '-'}}</el-descriptions-item>
                        <el-descriptions-item label="候选办理">{{ item.candidate || '-'}}</el-descriptions-item>
                        <el-descriptions-item label="接收时间">{{ item.createTime || '-'}}</el-descriptions-item>
                        <el-descriptions-item label="办结时间">{{ item.endTime || '-' }}</el-descriptions-item>
                        <el-descriptions-item label="耗时">{{ item.duration || '-'}}</el-descriptions-item>
                      </el-descriptions>
                      <div v-if="item.commentList && item.commentList.length > 0">
                        <div v-for="(comment, index) in item.commentList" :key="index">
                          <el-divider content-position="left">
                            <el-tag
                              :type="approveTypeTag(comment.type)"
                              size="mini"
                            >{{ commentType(comment.type) }}</el-tag>
                            <el-tag type="info" effect="plain" size="mini">{{ comment.time }}</el-tag>
                          </el-divider>
                          <span>{{ comment.fullMessage }}</span>
                        </div>
                      </div>
                    </el-card>
                    <el-card
                      v-if="item.activityType === 'endEvent'"
                      class="box-card"
                      shadow="hover"
                    >{{ item.createTime }} 结束流程</el-card>
                  </el-timeline-item>
                </el-timeline>
              </div>
            </el-col>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="流程跟踪" name="track">
          <el-skeleton v-if="formLoading" :rows="10" animated />
          <el-card class="box-card" shadow="never">
            <process-viewer
              :key="`designer-${loadIndex}`"
              :style="'height:' + height"
              :xml="xmlData"
              :finishedInfo="finishedInfo"
              :allCommentList="historyProcNodeList"
            />
          </el-card>
        </el-tab-pane>
      </el-tabs>
      <!--退回流程-->
      <el-dialog :title="returnTitle" :visible.sync="returnOpen" width="40%" :close-on-click-modal="false" append-to-body>
        <el-form ref="taskForm" :model="taskForm" label-width="80px">
          <el-form-item label="退回节点" prop="targetKey">
            <el-radio-group v-model="taskForm.targetKey">
              <el-radio-button
                v-for="item in returnTaskList"
                :key="item.id"
                :label="item.id"
              >{{item.name}}</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="returnOpen = false">取 消</el-button>
          <el-button type="primary" @click="submitReturn">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog :title="userData.title" :visible.sync="userData.open" width="60%" :close-on-click-modal="false" append-to-body>
        <el-row type="flex" :gutter="20">
          <!--部门数据-->
          <el-col :span="5">
            <el-card shadow="never" style="height: 100%">
              <div slot="header">
                <span>部门列表</span>
              </div>
              <div class="head-container">
                <el-input
                  v-model="deptName"
                  placeholder="请输入部门名称"
                  clearable
                  size="small"
                  prefix-icon="el-icon-search"
                />
                <el-tree
                  :data="deptOptions"
                  :props="deptProps"
                  :expand-on-click-node="false"
                  :filter-node-method="filterNode"
                  ref="tree"
                  default-expand-all
                  @node-click="handleNodeClick"
                />
              </div>
            </el-card>
          </el-col>
          <el-col :span="18">
            <el-table
              ref="userTable"
              :key="userData.type"
              height="500"
              v-loading="userLoading"
              :data="userList"
              highlight-current-row
              @current-change="changeCurrentUser"
              @selection-change="handleSelectionChange"
            >
              <el-table-column
                v-if="userData.type === 'copy' || userData.type === 'next'"
                width="55"
                type="selection"
              />
              <el-table-column v-else width="30">
                <template slot-scope="scope">
                  <el-radio :label="scope.row.userId" v-model="currentUserId">{{''}}</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="用户名" align="center" prop="nickName" />
              <el-table-column label="手机" align="center" prop="phonenumber" />
              <el-table-column label="部门" align="center" prop="dept.deptName" />
            </el-table>
            <pagination
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </el-col>
        </el-row>
        <span slot="footer" class="dialog-footer">
          <el-button @click="userData.open = false">取 消</el-button>
          <el-button type="primary" @click="submitUserData">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 打印窗口 -->
      <el-dialog v-if="dialogVisible" :title="dialogTile" :visible.sync="dialogVisible" @close="handelClose" width="60%" :close-on-click-modal="false" append-to-body>
        <div id="printBox">
          <img :src="barCode"  height="100px"/>
        <v-form-render v-for="(form,index) in printRes" :key="index" :form-json="form.fields" :form-data="form.field" ref="vFormRef"></v-form-render>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handelClose">取 消</el-button>
          <el-button ref="btnPrint" type="primary" v-print="printId" @click="submitPrint" v-loading.fullscreen.lock="fullscreenLoading">确 定</el-button>
        </span>
      </el-dialog>
    </div>
</template>

<script>
  import { detailProcess, listProcessGen } from "@/api/workflow/process";
  import moment from 'moment'
  // import Parser from "@/utils/generator/parser";
  import {
    complete,
    delegate,
    transfer,
    rejectTask,
    returnList,
    returnTask,
    submitList,
    updateFormList
  } from "@/api/workflow/task";
  import { selectUser, deptTreeSelect } from "@/api/system/user";
  import ProcessViewer from "@/components/ProcessViewer";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import Treeselect from "@riophae/vue-treeselect";

  export default {
    components: {
      ProcessViewer,
      // Parser,
      Treeselect
    },
    dicts: ['fa_status'],
    props: {},
    mounted() {
      this.routeQuery = this.$route.query;
    },
    computed: {
      commentType() {
        return val => {
          switch (val) {
            case "1":
              return '已审批';
            case "2":
              return "退回";
            case "3":
              return "驳回";
            case "4":
              return "委派";
            case "5":
              return "转办";
            case "6":
              return "终止";
            case "7":
              return "撤回";
          }
        };
      },
      approveTypeTag() {
        return val => {
          switch (val) {
            case "1":
              return "success";
            case "2":
              return "warning";
            case "3":
              return "danger";
            case "4":
              return "primary";
            case "5":
              return "success";
            case "6":
              return "danger";
            case "7":
              return "info";
          }
        };
      },
      _userInfo() {
          return this.$store.state.user.userInfo
        }
    },
    data() {
      return {
        routeQuery: {},
        form: {},
        size: "mini",
        // 遮罩层表单信息
        formLoading:true,
        // 全局loading
        fullscreenLoading: false,
        // 打印窗口
        dialogVisible: false,
        // 打印弹窗数据
        printRes: [],
        // 打印标题
        dialogTile:'打印窗口',
        // 条形码
        barCode:'',
        // 打印绑定对象
        printId: {
          id: 'printBox',
          openCallback(vue) {
            // vue.fullscreenLoading = false
          },
          //关闭打印的回调事件（无法确定点击的是确认还是取消）
          //函数中this指向当前print object对象，that返回Vue对象；
          closeCallback(vue) {
            // console.log(vue, 'vue');
            if (vue.editFlag == '0') {
              // console.log(vue,'66');
              if (Array.isArray(vue.formDisable)) {
              vue.formDisable.forEach(item => item.disableForm())
              vue.formDisable.forEach(item => item.enableWidgets('cut'))
            } else {
              vue.formDisable.disableForm()
              vue.formDisable.enableWidgets('cut')
            }

            } else {
              const vueObj = vue.formDisable.filter((item, index) => {
                return index != 0
              })
              vueObj.forEach(item => {item.disableForm()})
            }
            vue.fullscreenLoading = false
          }
        },
        objNew:{},
        // 表单数组
        formDisable:[],
        btnTitle:'通过',
        height: document.documentElement.clientHeight - 205 + "px;",
        // 模型xml数据
        loadIndex: 0,
        xmlData: undefined,
        finishedInfo: {
          finishedSequenceFlowSet: [],
          finishedTaskSet: [],
          unfinishedTaskSet: [],
          rejectedTaskSet: []
        },
        historyProcNodeList: [],
        // 部门名称
        deptName: undefined,
        // 部门树选项
        deptOptions: undefined,
        userLoading: false,
        // 用户表格数据
        userList: null,
        deptProps: {
          children: "children",
          label: "label"
        },
        // 查询参数
        queryParams: {
          deptId: undefined
        },
        total: 0,
        // 遮罩层
        loading: true,
        taskForm: {
          comment: "", // 意见内容
          procInsId: "", // 流程实例编号
          taskId: "", // 流程任务编号
          copyUserIds: "", // 抄送人Id
          vars: "",
          targetKey: "",
          variables:{}
        },
        // 编辑状态 0 不可编辑 1 可编辑
        editFlag: null,
        // 流程状态
        approvalStatus:null,
        rules: {
          comment: [
            { required: true, message: "请输入审批意见", trigger: "blur" }
          ]
        },
        currentUserId: null,
        variables: [], // 流程变量数据
        taskFormOpen: false,
        taskFormData: {}, // 流程变量数据
        processFormList: [], // 流程变量数据
        // 显示的表单
        processList:[],
        formOpen: false, // 是否加载流程变量数据
        returnTaskList: [], // 回退列表数据
        processed: false,
        returnTitle: null,
        returnOpen: false,
        rejectOpen: false,
        rejectTitle: null,
        userData: {
          title: "",
          type: "",
          open: false
        },
        copyUser: [],
        nextUser: [],
        userMultipleSelection: [],
        userDialogTitle: "",
        userOpen: false,
        businessType: null,
        // 申请编号
        serialCode: null,
        otherConfig:null,
      };
    },
    created() {
      this.initData();
    },
    methods: {
      userCheck() {
        // 当前时间
        const firstDate = moment().format('YYYY-MM-DD')
        this.$refs.vFormRefs.setFieldValue('feedback',this.taskForm.comment)
        this.$refs.vFormRefs.setFieldValue('signatory',this._userInfo.nickName)
        this.$refs.vFormRefs.setFieldValue('signatoryTime',firstDate)
      },
      returnGo() {
        this.$router.back(-1)
      },
      // 暂存表单
      handleupdateForm() {

        let Vform = this.$refs.vFormRefSubmit[0].getFormData(false)
        console.log(Vform,"机房设备进出");
        let saveObj = {
            complete:{
              assignee: "",
              candidateGroups:[],
              candidateUsers: [],
              comment: "",
              copyUserIds: "",
              nextUserIds: "",
              procInsId: this.taskForm.procInsId,
              targetKey: "",
              taskId: this.taskForm.taskId,
              taskName: "",
              userId: "",
              variables: {},

            },
             variables:Vform,
          }

        updateFormList(saveObj,this.businessType).then(res => {
            // if (res.code == 200) {
            this.$modal.msgSuccess(res.msg);
              this.$router.back(-1)
            // }
          })
      },
      // 提交表单
      handleCompleteSubmit() {
        this.$refs.vFormRefSubmit.forEach(item => item.getFormData().then(formData => {
          let saveObj = {
            complete:{
              assignee: "",
              candidateGroups:[],
              candidateUsers: [],
              comment: "",
              copyUserIds: "",
              nextUserIds: "",
              procInsId: this.taskForm.procInsId,
              targetKey: "",
              taskId: this.taskForm.taskId,
              taskName: "",
              userId: "",
              variables: {},

            },
             variables:formData,
          }
          submitList(saveObj,this.businessType).then(res => {
            // if (res.code == 200) {
            this.$modal.msgSuccess(res.msg);
              this.$router.back(-1)
            // }
          })
        }))

      },
      // 打印弹窗取消按钮
      handelClose() {
        this.printRes = []
        this.dialogVisible = false
      },
      // 打印 按钮
      printResList() {
        let flag = true
          this.processFormList.map((item, index, arr) => {
                  flag = true;
                  if (this.printRes.length < 1) {
                      this.printRes.push(item);
                  } else {
                      this.printRes.map((item2, index2, res) => {
                          if (item2.title === item.title) {
                              item2.field = item.field;
                              flag = false;
                          }
                      });
                      if (flag) {
                          this.printRes.push(item);
                      }
                  }
          });
      },
      async printClick() {
        // console.log(formInfo.field.cut, '11');
        // if (formInfo.field.cut) {
        //   this.$refs.vFormRefSubmit.forEach(item => {
        //     console.log(item, 'item');
        //     if (item.formDataModel.cut) {
        //       this.objNew = item
        //       formInfo.field.cut = this.objNew.formDataModel.cut
        //     }
        //   })
        // }

        // this.printList = formInfo
        // const res=await listProcessGen({
        //   procInsId:this.taskForm.procInsId
        // })
        //   let url = window.URL.createObjectURL(res)
        // console.log(url);
        // this.barCode = url
        this.printResList()
        this.dialogVisible = true
        this.$nextTick(() => {
          this.$refs.vFormRef.forEach(item => {
            item.showWidgets('serialCode')
            item.setFieldValue('serialCode',this.serialCode)
            item.disableForm()
          })
        })
      },
      // 确定打印按钮
      submitPrint() {
        // 打开表单编辑为了打印出暗色
        // 在关闭打印时再次把表单禁用掉（方法在data里面）
        this.$nextTick(() => {
            // console.log(this.$refs.vFormRef);
            this.formDisable = this.$refs.vFormRef
            // console.log(this.formDisable, "9");
            if (this.formDisable.length > 0) {
              this.formDisable.forEach((item) => {
                return [ item.enableForm(),item.enableWidgets('cut') ]
            })
            } else {
              this.$refs.vFormRef.enableForm()
              this.$refs.vFormRef.enableWidgets('cut')
          }
        })
        this.fullscreenLoading = true;

      },
      initData() {
        this.taskForm.procInsId =
          this.$route.params && this.$route.params.procInsId;
        this.taskForm.taskId = this.$route.query && this.$route.query.taskId;
        this.processed =
          this.$route.query && eval(this.$route.query.processed || false);
        // 流程任务重获取变量表单
        this.getProcessDetails(this.taskForm.procInsId, this.taskForm.taskId);
        this.loadIndex = this.taskForm.procInsId;
      },
      /** 查询部门下拉树结构 */
      getTreeSelect() {
        deptTreeSelect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查询用户列表 */
      getList() {
        this.userLoading = true;
        selectUser(this.addDateRange(this.queryParams, this.dateRange)).then(
          response => {
            this.userList = response.rows;
            this.total = response.total;
            this.toggleSelection(this.userMultipleSelection);
            this.userLoading = false;
          }
        );
      },
      // 筛选节点
      filterNode(value, data) {
        // console.log(value,data,"88890999");
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.deptId = data.id;
        this.getList();
      },
      setIcon(val) {
        if (val) {
          return "el-icon-check";
        } else {
          return "el-icon-time";
        }
      },
      setColor(val) {
        if (val) {
          return "#2bc418";
        } else {
          return "#b3bdbb";
        }
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.userMultipleSelection = selection;
      },
      toggleSelection(selection) {
        if (selection && selection.length > 0) {
          this.$nextTick(() => {
            selection.forEach(item => {
              let row = this.userList.find(k => k.userId === item.userId);
              this.$refs.userTable.toggleRowSelection(row);
            });
          });
        } else {
          this.$nextTick(() => {
            this.$refs.userTable.clearSelection();
          });
        }
      },
      // 关闭标签
      handleClose(type, tag) {
        let userObj = this.userMultipleSelection.find(
          item => item.userId === tag.id
        );
        this.userMultipleSelection.splice(
          this.userMultipleSelection.indexOf(userObj),
          1
        );
        if (type === "copy") {
          // console.log(this.userMultipleSelection,"shi");
          this.copyUser = this.userMultipleSelection;
          // 设置抄送人ID
          if (this.copyUser && this.copyUser.length > 0) {
            const val = this.copyUser.map(item => item.id);
            this.taskForm.copyUserIds =
              val instanceof Array ? val.join(",") : val;
          } else {
            this.taskForm.copyUserIds = "";
          }
        } else if (type === "next") {
          this.nextUser = this.userMultipleSelection;
          // 设置抄送人ID
          if (this.nextUser && this.nextUser.length > 0) {
            const val = this.nextUser.map(item => item.id);
            this.taskForm.nextUserIds =
              val instanceof Array ? val.join(",") : val;
          } else {
            this.taskForm.nextUserIds = "";
          }
        }
      },
      /** 流程变量赋值 */
      handleCheckChange(val) {

        if (val instanceof Array) {
          this.taskForm.values = {
            approval: val.join(",")
          };
        } else {
          this.taskForm.values = {
            approval: val
          };
        }
      },
      getProcessDetails(procInsId, taskId) {
        const params = { procInsId: procInsId, taskId: taskId };
        detailProcess(params).then(res => {
          // console.log(res, "88888888");
          const data = res.data;
          this.otherConfig = data.otherConfig
          this.serialCode = data.serialCode
          this.businessType = data.businessType
          this.editFlag = data.editFlag
          // this.showFormLocalScope = data.showFormLocalScope
          this.approvalStatus = data.approvalStatus
          this.xmlData = data.bpmnXml;
          this.processFormList = data.processFormList;
          this.processList.push(data.processFormList[0])
          this.processFormList.filter(formItem => {
            if (formItem.showFormLocalScope == true) {
              return this.processList.push(formItem)
            }
          })
          this.processFormList[0].title = data.projectName
          this.taskFormOpen = data.existTaskForm;
          if (this.taskFormOpen) {
            this.taskFormData = data.taskFormData;
          }
          this.historyProcNodeList = data.historyProcNodeList;

          this.finishedInfo = data.flowViewer;
          this.formOpen = true;
          this.$nextTick(() => {
            this.formDisable = this.$refs.vFormRefSubmit
            if (this.formDisable.length > 0) {
              this.formDisable.forEach((item) => {
                item.showWidgets('serialCode')
                item.setFieldValue('serialCode',this.serialCode)
                if (data.editFlag == 0) {
                  console.log(this.$vform,'widget');
                  return [ item.disableForm(),item.enableWidgets('cut') ]
                } else {
                  item.disableWidgets('serialCode')
                }
              })
            } else {
              this.$refs.vFormRef.disableForm()
              this.$refs.vFormRef.enableWidgets('cut')
            }
            if (this.taskFormOpen) {
              this.userCheck()
            }

          //   if (data.editFlag == 0) {
          //     // 禁用每一项Vform表单
          //   // console.log(this.$refs.vFormRef);
          //   if (this.formDisable.length > 0) {
          //     this.formDisable.forEach((item) => {
          //       item.showWidgets('serialCode')
          //       item.setFieldValue('serialCode',data.serialCode)
          //     // console.log(item,"77788887877");
          //       return [ item.disableForm(),item.enableWidgets('cut') ]
          //   })
          //   } else {

          //   }

          //   // this.$refs.vFormRef[0].disableForm()
          //   } else {
          //   // console.log('111');
          //   // // this.$nextTick(() => {
          //   //   // const formDisableNo = this.$refs.vFormRefSubmit
          //   //   // console.log(formDisableNo, 'formDisableNo');
          //   //   const formNo = this.formDisable.filter((element, index) => {
          //   //     return index != 0
          //   //   });
          //   //   console.log(formNo,'formNo');
          //   //   formNo.forEach(item => item.disableForm())
          // // })
          // }
          })
          // if (data.editFlag == 0) {
          //     // 禁用每一项Vform表单
          // this.$nextTick(() => {
          //   // console.log(this.$refs.vFormRef);
          //   this.formDisable = this.$refs.vFormRefSubmit
          //   console.log(this.formDisable, "9");
          //   if (this.formDisable.length > 0) {
          //     this.formDisable.forEach((item) => {
          //       item.showWidgets('serialCode')
          //       item.setFieldValue('serialCode',data.serialCode)
          //     // console.log(item,"77788887877");
          //       return [ item.disableForm(),item.enableWidgets('cut') ]
          //   })
          //   } else {
          //     this.$refs.vFormRef.disableForm()
          //     this.$refs.vFormRef.enableWidgets('cut')
          //   }

          //   // this.$refs.vFormRef[0].disableForm()
          // })
          // } else {
          //   this.$nextTick(() => {
          //     const formDisableNo = this.$refs.vFormRefSubmit
          //     console.log(formDisableNo, 'formDisableNo');
          //     const formNo = formDisableNo.filter((element, index) => {
          //       return index != 0
          //     });
          //     console.log(formNo,'formNo');
          //     formNo.forEach(item => item.disableForm())
          //   // this.formD = this.$refs.vFormRefSubmit[0]
          //     // this.$refs.vFormRef.disableForm()
          //     // this.$refs.vFormRef.enableWidgets('cut')

          //   // this.$refs.vFormRef[0].disableForm()
          // })
          // }
          this.formLoading = false;
        });
      },
      onSelectCopyUsers() {
        this.userMultipleSelection = this.copyUser;
        this.onSelectUsers("新增抄送人", "copy");
      },
      onSelectNextUsers() {
        this.userMultipleSelection = this.nextUser;
        this.onSelectUsers("指定审批人", "next");
      },
      onSelectUsers(title, type) {
        this.userData.title = title;
        this.userData.type = type;
        this.getTreeSelect();
        this.getList();
        this.userData.open = true;
      },
      /** 通过任务 */
      async handleComplete(type,specialBtn) {
        console.log(type,"type");
        console.log(specialBtn,"spec");
        // 校验表单
        // const taskFormRef = this.$refs.taskFormParser;
        // const isExistTaskForm = taskFormRef !== undefined;
        // // 若无任务表单，则 taskFormPromise 为 true，即不需要校验
        // const taskFormPromise = !isExistTaskForm
        //   ? true
        //   : new Promise((resolve, reject) => {
        //       taskFormRef.$refs[taskFormRef.formConfCopy.formRef].validate(
        //         valid => {
        //           valid ? resolve() : reject();
        //         }
        //       );
        //     });
        // const approvalPromise = new Promise((resolve, reject) => {
        //   this.$refs["taskForm"].validate(valid => {
        //     valid ? resolve() : reject();
        //   });
        // });
        // Promise.all([taskFormPromise, approvalPromise]).then(() => {
        //   if (isExistTaskForm) {
        //     this.taskForm.variables =
        //       taskFormRef[taskFormRef.formConfCopy.formModel];
        //   }
        //   complete(this.taskForm).then(response => {
        //     this.$modal.msgSuccess(response.msg);
        //     this.goBack();
        //   });
        // });
        if (type == 1) {
          this.taskForm.comment = this.taskForm.comment
        } else {
          if (this.taskForm.comment == "") {
            if (specialBtn) {
            this.taskForm.comment = specialBtn
            } else {
              this.taskForm.comment = '通过'
            }
          } else {
              this.taskForm.comment = this.taskForm.comment
            }
          }

        this.taskForm.btStatus = type
        this.$refs["taskForm"].validate(async valid => {
          if (valid) {
            if (!this.taskFormOpen) {
          const res = await complete(this.taskForm)
          this.$modal.msgSuccess(res.msg);
          this.goBack();
            } else {
              this.userCheck()
            const formData = await this.$refs.vFormRefs.getFormData()
            this.taskForm.variables = formData
            const res = await complete(this.taskForm)
            this.$modal.msgSuccess(res.msg);
            this.goBack();
        }
          }
         })


      },
      async handleEnsure() {
        this.taskForm.comment = '已确认'
        if (!this.taskFormOpen) {
          const res = await complete(this.taskForm)
          this.$modal.msgSuccess(res.msg);
          this.goBack();
            } else {
              this.userCheck()
            const formData = await this.$refs.vFormRefs.getFormData()
            this.taskForm.variables = formData
            const res = await complete(this.taskForm)
            this.$modal.msgSuccess(res.msg);
            this.goBack();
        }
      },
      async handleDispose() {
        this.taskForm.comment = '处理完成'
        if (!this.taskFormOpen) {
          const res = await complete(this.taskForm)
          this.$modal.msgSuccess(res.msg);
          this.goBack();
            } else {
              this.userCheck()
            const formData = await this.$refs.vFormRefs.getFormData()
            this.taskForm.variables = formData
            const res = await complete(this.taskForm)
            this.$modal.msgSuccess(res.msg);
            this.goBack();
        }
      },
      /** 委派任务 */
      handleDelegate() {
        this.$refs["taskForm"].validate(valid => {
          if (valid) {
            this.userData.type = "delegate";
            this.userData.title = "委派任务";
            this.userData.open = true;
            this.getTreeSelect();
          }
        });
      },
      /** 转办任务 */
      handleTransfer() {
        this.$refs["taskForm"].validate(valid => {
          if (valid) {
            this.userData.type = "transfer";
            this.userData.title = "转办任务";
            this.userData.open = true;
            this.getTreeSelect();
          }
        });
      },
      /** 拒绝任务 */
      handleReject() {
        // this.$refs["taskForm"].validate(valid => {
          // if (valid) {
            const _this = this;
            this.$modal
              .confirm("拒绝审批单流程会终止，是否继续？")
              .then(function() {
                return rejectTask(_this.taskForm);
              })
              .then(res => {
                this.$modal.msgSuccess(res.msg);
                this.goBack();
              });
          // }
        // });
      },
      changeCurrentUser(val) {
        this.currentUserId = val.userId;
      },
      /** 返回页面 */
      goBack() {
        // 关闭当前标签页并返回上个页面
        this.$tab.closePage(this.$route);
        this.$router.back();
      },
      /** 接收子组件传的值 */
      // getData(data) {
      //   if (data) {
      //     const variables = [];
      //     data.fields.forEach(item => {
      //       let variableData = {};
      //       variableData.label = item.__config__.label;
      //       // 表单值为多个选项时
      //       if (item.__config__.defaultValue instanceof Array) {
      //         const array = [];
      //         item.__config__.defaultValue.forEach(val => {
      //           array.push(val);
      //         });
      //         variableData.val = array;
      //       } else {
      //         variableData.val = item.__config__.defaultValue;
      //       }
      //       variables.push(variableData);
      //     });
      //     this.variables = variables;
      //   }
      // },
      submitUserData() {
        let type = this.userData.type;
        if (type === "copy" || type === "next") {
          if (
            !this.userMultipleSelection ||
            this.userMultipleSelection.length <= 0
          ) {
            this.$modal.msgError("请选择用户");
            return false;
          }
          let userIds = this.userMultipleSelection.map(k => k.userId);
          if (type === "copy") {
            // 设置抄送人ID信息
            this.copyUser = this.userMultipleSelection;
            this.taskForm.copyUserIds =
              userIds instanceof Array ? userIds.join(",") : userIds;
          } else if (type === "next") {
            // 设置下一级审批人ID信息
            this.nextUser = this.userMultipleSelection;
            this.taskForm.nextUserIds =
              userIds instanceof Array ? userIds.join(",") : userIds;
          }
          this.userData.open = false;
        } else {
          if (!this.taskForm.comment) {
            this.$modal.msgError("请输入审批意见");
            return false;
          }
          if (!this.currentUserId) {
            this.$modal.msgError("请选择用户");
            return false;
          }
          this.taskForm.userId = this.currentUserId;
          if (type === "delegate") {
            delegate(this.taskForm).then(res => {
              this.$modal.msgSuccess(res.msg);
              this.goBack();
            });
          }
          if (type === "transfer") {
            transfer(this.taskForm).then(res => {
              this.$modal.msgSuccess(res.msg);
              this.goBack();
            });
          }
        }
      },
      /** 可退回任务列表 */
       handleReturn() {
        if (this.taskForm.comment == "" || this.taskForm.comment == "通过") {
          this.taskForm.comment = ''
        }
        this.$refs["taskForm"].validate( async valid => {
          if (valid) {
        //     this.returnTitle = "退回流程";

            if (!this.taskFormOpen) {
              const res  = await returnList(this.taskForm)
              // console.log(res);
              if (res.data) {
                this.returnTaskList = res.data;
                let taskObj = this.returnTaskList.at(-1)
                this.taskForm.targetKey = taskObj.id
                this.taskForm.values = null;
                returnTask(this.taskForm).then(res => {
                  this.$modal.msgSuccess(res.msg);
                  this.goBack();
                });
              }
            } else {
              const res  = await returnList(this.taskForm)
                // console.log(res);
                if (res.data) {
                  this.returnTaskList = res.data;
                  let taskObj = this.returnTaskList.at(-1)
                  this.taskForm.targetKey = taskObj.id
                  this.taskForm.values = null;
                  this.userCheck()
                  const formData = await this.$refs.vFormRefs.getFormData()
                  this.taskForm.variables = formData
                  returnTask(this.taskForm).then(res => {
                    this.$modal.msgSuccess(res.msg);
                    this.goBack();
                  });
                }
             }


              // this.returnOpen = true;
            // });
          }
        });
      },
      /** 提交退回任务 */
      submitReturn() {
        this.$refs["taskForm"].validate(valid => {
          if (valid) {
            if (!this.taskForm.targetKey) {
              this.$modal.msgError("请选择退回节点！");
            }
            // returnTask(this.taskForm).then(res => {
            //   this.$modal.msgSuccess(res.msg);
            //   this.goBack();
            // });
          }
        });
      }
    }
  };
  </script>
  <style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    height: 70vh;
    overflow-y: scroll;
  }
  .todoFlex {
    display: flex;
    justify-content: space-between;
  }
  .headerTitle {
    display: flex;
    justify-content: space-between;
  }
  .el-card ::v-deep .el-card__header {
    background-color: #8FC4F9;
  }
  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both;
  }
  .box-Print {
    margin-top: 20px;
    // margin-bottom: 20px;
  }
  .taskPrint {
    display: flex;
    justify-content: space-between;
  }
  .box-card {
    width: 100%;
    margin-bottom: 20px;
  }

  .el-tag + .el-tag {
    margin-left: 10px;
  }

  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
  }

  .button-new-tag {
    margin-left: 10px;
  }
  </style>
  <style>
  @media print {
    @page {
      size:  auto;
    }
    body, html {
      height: auto !important;
    }
  }
  </style>
